import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_tutorial/app/core/lang/custom_translations.dart';
import 'package:getx_tutorial/app/routes/app_pages.dart';

import 'app/core/utils/logger.dart';
import 'app/data/services/db_service.dart';
import 'app/data/services/settings_service.dart';

void main() async {
  await initServices();
  runApp(const MyApp());
}

Future<void> initServices() async {
  print('starting services ...');
  await Get.putAsync(() => DbService().init());
  await Get.put(SettingsService()).init();
  print('All services started...');
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,

      // 路由配置
      initialRoute: AppPages.INITIAL,
      defaultTransition: Transition.fade,
      getPages: AppPages.pages,
      unknownRoute: AppPages.unknownPage,

      translations: CustomTranslations(),
      locale: Locale('zh', 'CN'), // 指定默认翻译语言
      fallbackLocale: Locale('en', 'US'), // 翻译失败时，使用的语言

      // 启用日志
      enableLog: true, // 启用日志
      logWriterCallback: Logger.write, // 注册日志回调

      // initialBinding: SplashBinding(),
      // home: SplashPage(),
      // theme: appThemeData,
    );
  }
}